#include <vector>

namespace IntegrateScore {
    /*
     * cluster_score_l (n_classifier * n_query * n_cluster)
     * weight_l_l (n_classifier * n_item * n_overlap)
     * label_l_l (n_classifier * n_item * n_overlap)
     */

    void
    dot_product(std::vector<float> &score_table, std::vector<float *> &cluster_score_l, std::vector<float *> &weight_l_l
                , std::vector<int *> &label_l_l, int n_cluster, int query_idx, int n_overlap) {
        int n_item = (int) score_table.size();
        int n_classifier = (int) cluster_score_l.size();
        for (int i = 0; i < n_item; i++) {
            score_table[i] = 1;
        }
        for (int i = 0; i < n_classifier; i++) {
            float *tmp_cls_score_l = cluster_score_l[i] + query_idx * n_cluster;
            float *tmp_weight_l_l = weight_l_l[i];
            int *tmp_label_l_l = label_l_l[i];
            for (int j = 0; j < n_item; j++) {
                float *tmp_weight = tmp_weight_l_l + j * n_overlap;
                int *tmp_label = tmp_label_l_l + j * n_overlap;
                float tmp_score = 0;
                for (int k = 0; k < n_overlap; k++) {
                    tmp_score += tmp_cls_score_l[tmp_label[k]] * tmp_weight[k];
                }
                score_table[j] *= tmp_score;
            }
        }
    }

}
